package com.AAL.DAO;

import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.ILogDetailsForStockDAO;
import com.AAL.Model.LogDetailsForStock;
import com.AAL.Model.LogForStock;
import com.AAL.Utils.HibernateUtil;

public class LogDetailsForStockDAO implements ILogDetailsForStockDAO{

	@Override
	public LogDetailsForStock saveAndUpdateLogDetailsForStock(
			LogDetailsForStock logDetailForStock) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		try {
			session.saveOrUpdate(logDetailForStock);
		} catch (Exception e) {
			return null;
		}
		session.getTransaction().commit();
		return logDetailForStock;
	}

	@Override
	public LogDetailsForStock deteleLogDetailForStock(int logDetailForStockID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		try {
			session.beginTransaction();
			LogDetailsForStock logDetailForStock = (LogDetailsForStock) session.load(
					LogDetailsForStock.class, logDetailForStockID);
			if (null != logDetailForStock) {
				session.delete(logDetailForStock);
			}
			session.getTransaction().commit();
			return logDetailForStock;
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
			return null;
		}
	}

	@Override
	public LogDetailsForStock getLogDetailForStock(int logDetailForStockID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		LogDetailsForStock logDetailForStock = (LogDetailsForStock) session.load(LogDetailsForStock.class, logDetailForStockID);
		return logDetailForStock;
	}

	@Override
	public LogDetailsForStock getLstDetailForStockByLogForStock(
			LogForStock logForStock) {
		// TODO Auto-generated method stub
		return null;
	}

}
